---
title: GitRepository generator
hide_title: true
---

import TierLabel from "../_components/TierLabel";

# GitRepository generator <TierLabel tiers="enterprise" />

The `gitRepository` generator allows you to generate resources from the contents of files in a Git repository.

### Example

```yaml
apiVersion: templates.weave.works/v1alpha1
kind: GitOpsSet
metadata:
  labels:
    app.kubernetes.io/name: gitopsset
    app.kubernetes.io/instance: gitopsset-sample
    app.kubernetes.io/part-of: gitopssets-controller
    app.kubernetes.io/managed-by: kustomize
    app.kubernetes.io/created-by: gitopssets-controller
  name: repository-sample
spec:
  generators:
    - gitRepository:
        repositoryRef: go-demo-repo
        files:
          - path: examples/generation/dev.yaml
          - path: examples/generation/production.yaml
          - path: examples/generation/staging.yaml
  templates:
    - content:
        kind: Kustomization
        apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
        metadata:
          name: "{{ .element.env }}-demo"
          labels:
            app.kubernetes.io/name: go-demo
            app.kubernetes.io/instance: "{{ .element.env }}"
            com.example/team: "{{ .element.team }}"
        spec:
          interval: 5m
          path: "./examples/kustomize/environments/{{ .element.env }}"
          prune: true
          sourceRef:
            kind: GitRepository
            name: go-demo-repo

```

In this example, a [Flux `GitRepository`](https://fluxcd.io/flux/components/source/gitrepositories/) called `go-demo-repo` in the same namespace as the `GitOpsSet` will be tracked, and `Kustomization` resources are generated from the three files listed.

These files can be JSON or YAML.

In this example we expect to find the following structure in the files:

```yaml title=examples/generation/dev.yaml
env: dev
team: developers
```

Changes pushed to the `GitRepository` will result in rereconciliation of the templates into the cluster.

For security reasons, you need to explicitly list out the files that the generator should parse.

import RBACWarning from './_rbac_warning.mdx';

<RBACWarning />